package com.guigu.youxuan.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.youxuan.pojo.Warehouse;
import com.guigu.youxuan.pojo.WarehouseDetails;
import com.guigu.youxuan.service.IWarehouseDetailsService;
import com.guigu.youxuan.service.impl.WarehouseDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/warehouseDetails")
public class WarehouseDetailsController {
    @Autowired
    private IWarehouseDetailsService iWarehouseDetailsService;

    /**
     * 根据商品id查询仓库商品表里面的当前库存
     * @param goodsId
     * @return
     */
    @RequestMapping("/queryWarehouseByGid/{goodsId}")
    @ResponseBody
    public WarehouseDetails queryWarehouseByGid(@PathVariable Long goodsId) {
        WarehouseDetails warehouseDetails = iWarehouseDetailsService.queryWarehouseByGid(goodsId);
        return warehouseDetails;
    }


    /**
     * 查询商品的当前库存
     * @param goodsId
     * @return
     */
    @RequestMapping("/queryGoodsAmount/{goodsId}")
    @ResponseBody
    private Integer queryGoodsAmount(@PathVariable Long goodsId) {
        Integer num = iWarehouseDetailsService.queryGoodsAmount(goodsId);
        return num;
    }
    
    /**
     * 分页查询仓库商品表
     * @param currentPage
     * @param pageSize
     * @return
     * @return
     */
    @RequestMapping("/DynamicListPage/{currentPage}/{pageSize}")
    @ResponseBody
    public PageInfo<WarehouseDetails> DynamicListPage(@PathVariable int currentPage,
                                                 @PathVariable int pageSize
    ){
        PageInfo<WarehouseDetails> page=this.iWarehouseDetailsService.DynamicListPage(currentPage,pageSize);
        return page;
    }
}
